package com.ckg.service.impl;

import com.ckg.bean.User;
import com.ckg.util.DatabaseConnectionPool;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class UserService implements InitializingBean, DisposableBean {
    private DatabaseConnectionPool pool;
    private String configFile;

    public void setPool(DatabaseConnectionPool pool) {
        System.out.println("⚙️ 属性注入: DatabaseConnectionPool");
        this.pool = pool;
    }

    public void setConfigFile(String configFile) {
        System.out.println("⚙️ 属性注入: configFile=" + configFile);
        this.configFile = configFile;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("💥 接口销毁: 保存最后状态");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("🚀 接口初始化: 加载配置文件 " + configFile);
        pool.executeQuery("SELECT COUNT(*) FROM users");
    }

    public void createUser(User user) {
        System.out.println("👤 创建用户: " + user.getUsername());
        pool.executeQuery("INSERT INTO users ...");
    }
}

